package jc18;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;

public class fanshe1 {
    @Test
    public void getfan() throws Exception {
        Class<?> clazz = Class.forName("jc18.Student");
        Class<?> clazz1 = new Student().getClass();
        Class<?> clazz2 = Student.class;
        System.out.println(clazz.getName());
        System.out.println(clazz1.getPackage().getName());
        System.out.println(clazz2.getSimpleName());
        Student s1=new Student("王五",85);
        Student s2=new Student("张三",845);
        Student s3=new Student("李四",55);
        Student[] s={s1,s2,s3};
        System.out.println(Arrays.toString(s));
        for(Student s4:s){
            s4.eat(5);
            s4.play();
            System.out.println(s4.name);
            System.out.println(s4.age);
        }
    }
    @Test
    public void getshe(){
        Class<?> x = Student.class;
        Method[] m = x.getMethods();
        for (Method zs:m){
            System.out.println(zs);
            System.out.println(zs.getName());
            Class<?>[] p = zs.getParameterTypes();
            System.out.println(Arrays.toString(p));
        }
    }

    @Test
    public void gets(){
        Class<?> c = new Student().getClass();
        Constructor<?>[] m = c.getConstructors();
        for (Constructor a:m){
            System.out.println(a.getName());
            Class[] p1 = a.getParameterTypes();
            System.out.println(Arrays.toString(p1));
        }
    }
}
